#!/bin/sh

processType=$1


cd /home/xeniaprod/scripts/rcoos/alerts

startTime=`date -u`

if [ "$processType" = "saveAlert" ] 
  then
    echo "Start time: $startTime" >/var/www/xenia/tmp/log/saveAlert.log 2>&1
    echo "XML parameter: $2" >>/var/www/xenia/tmp/log/saveAlert.log 2>&1
    /usr/bin/python /usr/lib/python2.5/site-packages/xeniatools/emailAlertSystem.py --XMLConfigFile=/home/xeniaprod/config/emailAlertsConfig.xml --SaveAlert --XML=$2 >>/var/www/xenia/tmp/log/saveAlert.log 2>&1
    endTime=`date -u`
    echo "End time: $endTime" >>/var/www/xenia/tmp/log/saveAlert.log 2>&1

elif [ "$processType" = "unsubscribeAlert" ]
  then
    echo "Start time: $startTime" > /var/www/xenia/tmp/log/unsubscribeAlerts.log 2>&1

    echo "Unsubscribe parameter: $2" >> /var/www/xenia/tmp/log/unsubscribeAlerts.log 2>&1
    /usr/bin/python /usr/lib/python2.5/site-packages/xeniatools/emailAlertSystem.py --XMLConfigFile=/home/xeniaprod/config/emailAlertsConfig.xml -u --UnsubscribeParams=$2 >> /var/www/xenia/tmp/log/unsubscribeAlerts.log 2>&1
    retVal=$?
    echo "Return value: $retVal" >> /var/www/xenia/tmp/log/unsubscribeAlerts.log 2>&1

    endTime=`date -u`
    echo "End time: $endTime" >> /var/www/xenia/tmp/log/unsubscribeAlerts.log 2>&1

    echo "$retVal"

elif [ "$processType" = "checkEmail" ]
  then
    echo "Start time: $startTime" > /var/www/xenia/tmp/log/checkemailAlerts.log 2>&1

    /usr/bin/python /usr/lib/python2.5/site-packages/xeniatools/emailAlertSystem.py --XMLConfigFile=/home/xeniaprod/config/emailAlertsConfig.xml --CheckAlerts >> /var/www/xenia/tmp/log/checkemailAlerts.log 2>&1

    endTime=`date -u`
    echo "End time: $endTime" >> /var/www/xenia/tmp/log/checkemailAlerts.log 2>&1

elif [ "$processType" = "createObsFile" ]
  then
    echo "Start time: $startTime" > /var/www/xenia/tmp/log/checkemailAlerts.log 2>&1

    /usr/bin/python /home/xeniaprod/scripts/rcoos/alerts/AlertsPageDBQueryRev2.py --XMLConfigFile=/home/xeniaprod/config/emailAlertsConfig.xml --bbox "-82 31.65, -82 32.5, -74 37, -74 31.65, -82 31.65" --jsonfilename=/home/xeniaprod/scripts/rcoos/alerts/rcoostst.json >> /var/www/xenia/tmp/log/checkemailAlerts.log 2>&1

    endTime=`date -u`
    echo "End time: $endTime" >> /var/www/xenia/tmp/log/checkemailAlerts.log 2>&1

fi
